﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerFrame
{
    class Objpool<T> //泛型类，里面的内容都是T类型
    {
        public Stack<T> pool; //构建栈储存读写池，栈里面都是T类型
        public Objpool(int max)
        {
            pool = new Stack<T>(max); //栈中最多有max位
        }
        /// <summary>
        /// 入栈
        /// </summary>
        /// <param name="item">将类型为T的类型入栈</param>
        public void Push(T item)
        {
            pool.Push(item);
        }
        /// <summary>
        /// 出栈
        /// </summary>
        /// <returns>返回出栈的内容</returns>
        public T Pop()
        {
            return pool.Pop();
        }
        /// <summary>
        /// 返回pool中的数量
        /// </summary>
        public int Count
        {
            get{
                return pool.Count;
            }
        }
        /// <summary>
        /// 清空栈列
        /// </summary>
        public void Clear()
        {
            pool.Clear();
        }
    }
}
